package com.kang.util;

import cn.hutool.http.server.HttpServerResponse;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.server.reactive.ServerHttpResponse;

import java.util.HashMap;
import java.util.Map;

public class AuthFailResponse {

    public static DataBuffer authFailResponse(String status, String mag, ServerHttpResponse response) {
        Map<String,Object> map = new HashMap<>();
        map.put("code", status);
        map.put("msg",status);
        ObjectMapper objectMapper = new ObjectMapper();
        byte[] bytes = new byte[0];
        try {
            bytes = objectMapper.writeValueAsBytes(map);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return response.bufferFactory().wrap(bytes);
    }

}
